import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author mjy
 * @date 2021/10/26
 * @description
 */
public class TCPThreadServerSocket implements Runnable {

    private Socket socket = null;
    private InputStream in = null;
    private OutputStream out = null;


    public TCPThreadServerSocket(Socket s) {
        this.socket = s;
    }


    @Override
    public void run() {
        try {
            in = socket.getInputStream();
            Date day=new Date();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(df.format(day));
            //服务端返回的消息
            out = socket.getOutputStream();
            byte[] recData = new byte[1024];
            int length = in.read(recData);
            String hc = new String(recData, 0, length);
            System.out.println("读取到客户端发送来的数据：" + hc);
            //返回给客户端的消息
            out.write("REG".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                //关闭资源
                in.close();
                out.close();
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


}
